<?php
session_save_path('sessions');
session_start();

// Check if we're in a valid session. If yes, do appropriate logging.
if( isset($_SESSION['user']) && $_SESSION['user'] != null ) {
    // Include the user class
    include_once("include/user.php");

    // Include our activity logger
    include_once("include/activityLogger.php");
    
    // Include the database connection (seems that Concordia can't handle itself without it)
    include_once("include/dbconnection.php");
    
    // Create a logger object
    $logger = new ActivityLogger($TABLE_LOGS, $TABLE_LOGS_LOGGEDAT, $TABLE_LOGS_USERID, $TABLE_LOGS_ACTIVITYTYPE, $TABLE_LOGS_EXTRACOMMENTS, $TABLE_LOGS_ID);
    
    // Create a variable to store our user if we're validated
    $user = null;    
    
    // Unserialize our user to turn it back into a useful object
    $user = unserialize($_SESSION['user']);

    // Log the activity
    $logger->addLogging($user->getUserID(), $TABLE_ACTIVITYTYPES_LOGGEDOUT, $_SERVER['REMOTE_ADDR']);
    
    // Close the connection
    mysql_close();
}

session_destroy();

header("location:index.php");
?>
